﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HtmlAddPictures
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string line;
                string[] tokens;
                FileStream inFile = new FileStream(@"input.txt", FileMode.Open);
                StreamReader sr = new StreamReader(inFile, System.Text.Encoding.Default);
                FileStream outFile1 = new FileStream(@"result.txt", FileMode.Create);
                StreamWriter sw1 = new StreamWriter(outFile1, System.Text.Encoding.Default);
                FileStream outFile2 = new FileStream(@"resultbgc.txt", FileMode.Create);
                StreamWriter sw2 = new StreamWriter(outFile2, System.Text.Encoding.Default);
                FileStream outFile3 = new FileStream(@"resultblogger.txt", FileMode.Create);
                StreamWriter sw3 = new StreamWriter(outFile3, System.Text.Encoding.Default);
                line = sr.ReadLine();
                int n = int.Parse(line);
                for (int i = 0; i < n; i++)
                {
                    line = sr.ReadLine();
                    tokens = line.Split('\t');
                    int width, height;
                    if (int.Parse(tokens[3]) == 0)
                    {
                        width = 640;
                        height = 484;
                    }
                    else
                    {
                        width = 484;
                        height = 640;
                    }
                    string str1 = string.Format("[caption id=\"\" align=\"alignnone\" width=\"484\" caption=\"{2}\"]<img class=\" \" title=\"{1}\" src=\"{0}\" alt=\"{2}\" width=\"{3}\" height=\"{4}\" />[/caption]",tokens[0],tokens[1],tokens[2],width,height);
                    sw1.WriteLine();
                    sw1.WriteLine();
                    sw1.Write(str1);
                    string str2 = string.Format("[img]{0}[/img]",tokens[0]);
                    sw2.WriteLine(str2);
                    sw2.WriteLine(tokens[2]);
                    string str3 = string.Format("<table cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto; margin-right: auto; text-align: center;\"><tbody><tr><td style=\"text-align: center;\"><a href=\"{0}\" imageanchor=\"1\" style=\"clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;\"><img border=\"0\" height=\"{3}\" src=\"{0}\" width=\"{2}\" /></a></td></tr><tr><td class=\"tr-caption\" style=\"text-align: center;\">{1}</td></tr></tbody></table>", tokens[0], tokens[2], width, height);
                    sw3.WriteLine(str3);
                }
                sr.Close();
                sw1.Close();
                sw2.Close();
                sw3.Close();
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }
        }
    }
}
